<template>
  <hierTree v-if="show&&attrs" :data="anc.dataSet.treeData" v-bind="attrs" :ref="ref"
    @onload="onload"
    @select="select"
    @contextmenu="contextmenu"
    @add="add"
    @remove="remove"
    @menu="menu"></hierTree>
</template>

<script>
const ref='tree';
export default {
  name:ref,
  components: {},
  inject:['anc'],
  data() {
    return {
      ref,
      show:false,
      attrs:null,
    };
  },
  props: {},
  watch: {},
  computed: {},
  created() {
    this.beforePageInit();
  },
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
      this.pageInit();
    });
  },
  methods: {
    /**
     * 页面加载前初始化
     */
    beforePageInit(){
      this.attrs = this.attrsTpl();
      this.show = true;
    },
    /**
     * 页面加载后初始化
     */
    pageInit(){

    },
    /**
     * @description: 获取表格属性
     * @param {*} attr
     * @return {*}
     */
    attrsTpl() {
      return {
        rootEnable:true,//是否显示根节点
        title:'title',//根节点标题
        rootId:'root',//根节点id
        //子节点配置
        nameId:'id',//节点id字段名
        nameTitle:'title',//节点标题字段名
        namePid:'parentId',//节点父节点id字段名
        menuEnable:true,//是否显示菜单
        addEnable:true,//是否显示添加按钮
        removeEnable:true,//是否显示删除按钮;根节点不支持删除
        rootRender:null,//自定义根节点渲染函数,传入函数如(h, { root, node, data })=>{},渲染优先级为data项优先级最高
        childrenRender:null,//自定义子节点渲染函数,传入函数如(h, { root, node, data })=>{},渲染优先级为data项优先级最高
        menus:[//自定义菜单配置，菜单配置参考DropdownItem
            {
                title:'菜单1',//菜单标题
                disabled:false,//是否禁用
                menuStyle:{}//菜单样式
            }
        ],
      };
    },
    /**
     * 事件：表格加载后获取表格实例
     * @param tableIns 表格实例，相当于 this.$refs[this.ref]
     */
    load(tableIns){

    },
    select(item,data){
      
    },
    contextmenu(item,e,position){
      // this.select(this.data[0])
      // this.setTree(tree=>{
      //     tree.handleSelect(0)
      // })
    },
    add(item){

    },
    remove(item){

    },
    menu(menu,item){
        
    },
    setTree(fn){
      this.$children[0].setTree(fn)
    },
    handleSelect(nodeKey){
      this.$children[0]. handleSelect(nodeKey)
    },
    findTreeNode(key,value){
      return this.$children[0].findTreeNode(key,value)
    },
    getTree(){
      return this.$children[0].getTree();
    },
    getTreeData(){
      return this.$children[0].getTreeData();
    },
  }
};
</script>
<style scoped>
</style>